<template>
  <div class="p-a">
    <span
      class="fadeIn-p"
      @mousemove="handleMouseMove"
      @mouseout="handleMouseOut"
      @click="clickLink"
      >{{
        isOmit
          ? props.label.length > 18
            ? props.label.substring(0, 18) + "..."
            : props.label
          : props.label
      }}</span
    >
    <div v-show="isHidden" class="p-a-dropdown">
      {{ props.label }}
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";

const props = defineProps({
  label: {
    type: String,
    default: null,
  },
  isOmit: {
    type: Boolean,
    default: false,
  },
});

const isHidden = ref(false);
const handleMouseMove = () => {
  isHidden.value = true;
};
const handleMouseOut = () => {
  isHidden.value = false;
};
const clickLink = () => {
  window.$message.success(props.label);
  setTimeout(() => {
    window.open(props.label, "_blank");
  }, 1000);
};
</script>

<style scoped>
.p-a {
  margin: 5px 0px 10px 0px;
  position: relative;
}

.p-a-dropdown {
  /* width: 100%; */
  white-space: nowrap; /* 让文字不换行 */
  position: absolute;
  background: rgb(251, 251, 250);
  opacity: 1;
  margin: 10px 0px;
  padding: 10px;
  border-radius: 5px;
  z-index: 999;
  animation: dropdown 0.3s;
  box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.12);
}

@keyframes dropdown {
  0% {
    transform: scale(0.1);
    opacity: 0.1;
  }

  50% {
    transform: scale(1.05);
    opacity: 1;
  }

  70% {
    transform: scale(0.9);
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* 操纵before结合hover实现循序渐进的下划线 */
.fadeIn-p {
  text-decoration: none;
  color: #333;
  position: relative;
  cursor: pointer;
  display: inline-block;
  padding: 2px;
}

.fadeIn-p::before {
  content: "";
  position: absolute;
  bottom: 0px;
  left: 0;
  height: 2px;
  background-color: #3adb1d;
  width: 0;
  -webkit-transition: width 0.2s linear;
  transition: width 0.2s linear;
}

.fadeIn-p:hover::before {
  width: 100%;
  -webkit-transition: width 0.2s linear;
  transition: width 0.2s linear;
}
</style>
